package com.hailiao.beidou.message.bd.constant

import androidx.compose.ui.graphics.Color
import com.hailiao.beidou.message.bd.R
import com.hailiao.beidou.standard2.BDBSI_Data
import com.hailiao.beidou.standard3.BDPWI_Data

/**
 * 北斗状态
 * @Author d10ng
 * @Date 2023/11/15 15:47
 */
enum class BDStatus(
    val iconID: Int,
    val tips: String,
    val color: Color,
    // 是否已连接
    val isConnected: Boolean
) {
    // 断开连接，未连接
    DISCONNECT(R.drawable.bd_status_disconnect, "当前未连接北斗设备", Color(0xFFFFDFD5), false),
    // 连接中，所有连接上的设备都属于连接中状态，等待信号值刷新，才能变更成其他状态
    CONNECTING(R.drawable.bd_status_connecting, "正在连接北斗设备...", Color(0xFFD0F7DB), false),
    // 已连接
    CONNECTED(R.drawable.bd_status_connected, "北斗通讯信号正常", Color(0xFFE6E6E6), true),
    // 信号弱
    WEAK(R.drawable.bd_status_signal_weak, "北斗通讯信号弱", Color(0xFFFFF5D5), true),
    // 无信号
    NONE(R.drawable.bd_status_signal_none, "北斗无信号，请确保天线朝南且无遮挡物", Color(0xFFFFDFD5), true),

    ;

    companion object {
        fun parse(data: BDPWI_Data): BDStatus {
            val list = data.newBeamStatusList
            return when {
                list.any { it.s2cdCnr > 40 || it.s2cpCnr > 40 } -> CONNECTED
                list.any { it.s2cdCnr > 0 || it.s2cpCnr > 0 } -> WEAK
                else -> NONE
            }
        }

        fun parse(data: BDBSI_Data): BDStatus {
            val list = data.beamPowerList
            return when {
                list.any { it == 4 } -> CONNECTED
                list.any { it > 0 } -> WEAK
                else -> NONE
            }
        }
    }
}